﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using ITProject.Domain.Entities;

namespace ITProject.WebUI.Models
{
    public class AccountRegistrationViewModel : BaseViewModel
    {
        #region "Properties"

        [Required(ErrorMessage="Imię musi być podane")]
        [Display(Name="Imię")]
        [MaxLength(30, ErrorMessage="Za długie imię")]
        public string Name { get; set; }
        [Required(ErrorMessage = "Nazwisko musi być podane")]
        [Display(Name="Naziwsko")]
        [MaxLength(30, ErrorMessage = "Za długie nazwisko")]
        public string Surname { get; set; }
        [Required(ErrorMessage = "Data urodzenia musi być podana")]
        [DataType(DataType.Date, ErrorMessage = "Wpisz poprawną datę w formacie dd/mm/yyyy")]
        [Display(Name="Data urodzenia")]
        public DateTime BirthDate { get; set; }
        [Required(ErrorMessage = "Email musi być podany")]
        [Display(Name="Email")]
        [MaxLength(30, ErrorMessage = "Za długi adres email")]
        [RegularExpression(@"^[_A-Za-z0-9-]+@[A-Za-z0-9]+.[A-Za-z0-9]{2,}", ErrorMessage="Zły format adresu email")]
        public string Mail { get; set; }
        [Required(ErrorMessage = "Login musi być podany")]
        [Display(Name="Login")]
        [MaxLength(20, ErrorMessage = "Za długi login")]
        public string Login { get; set; }
        [Required(ErrorMessage = "Hasło musi być podane")]
        [Display(Name="Hasło")]
        public string Password { get; set; }
        [Required(ErrorMessage = "Hasło musi być powtórzone")]
        [Display(Name = "Powtórz hasło")]
        public string Password2 { get; set; }
        [Display(Name="Płeć")]
        public string Sex { get; set; }
        #endregion

        #region "Converters"

        public static User Convert(AccountRegistrationViewModel viewModel)
        {
            User newUser = new User();
            newUser.BirthDate = viewModel.BirthDate;
            newUser.Email = viewModel.Mail;
            newUser.FirstName = viewModel.Name;
            newUser.LastName = viewModel.Surname;
            newUser.Login = viewModel.Login;
            newUser.Password = viewModel.Password;
            newUser.RegisterDate = DateTime.Now;
            newUser.LastVisit = null;
            newUser.State = 2;
            newUser.Role = 1;
            newUser.Sex = viewModel.Sex;
            return newUser;
        }

        #endregion
    }
}